package day13_Io.demo02_FileOutPutStream;

import java.io.File;
import java.io.FileInputStream;


public class Demo10_Row {
    static int sum=0;

    public static void main(String[] args) throws Exception {
        File file = new File("E:\\csw\\Demo\\src");
        show(file);
        System.out.println(sum);
    }

    public static void show(File file) throws Exception {
        File[] files = file.listFiles();//获取所有对象
        //循环判断是文件还是目录
        for (File file1 : files) {
            if (file1.isFile()) {//判断抽象路径是否为文件
                String name = file1.getName();
                if (name.endsWith(".java")) {//后缀为.java统计行数
                    FileInputStream fis = new FileInputStream(file1.getAbsolutePath());//返回抽象路径的绝对路径字符串
                    int i;
                    while ((i = fis.read()) != -1) {
                        if ((char) i == '\n') {
                            sum++;
                        }
                    }
                    fis.close();
                }
            }
            else {
                show(file1);
            }
        }
    }
}
